package servlets;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import ufc.quixada.petti.infra.SimplesEntityManager;
import ufc.quixada.petti.model.Participante;
import ufc.quixada.petti.service.CredenciamentoEventoParticipanteService;
import ufc.quixada.petti.service.ParticipanteService;


@WebServlet("/listaParticipantes")
public class listaParticipantes extends HttpServlet {
	private static final long serialVersionUID = 1L;

	private String persistenceUnitName = "seven1";

	private SimplesEntityManager simplesEntityManager = new SimplesEntityManager(persistenceUnitName);
	private CredenciamentoEventoParticipanteService credenciamentoEvParticipanteService= new CredenciamentoEventoParticipanteService(simplesEntityManager);
        private ParticipanteService ParticipanteService= new ParticipanteService(simplesEntityManager);
	private List<Participante> listaParticipantes = new ArrayList<>();
        private List<Long> listaIdsParticipantes= new ArrayList<Long>();
	public listaParticipantes() {
		super();

	}
        
        

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

                String idEvento=request.getParameter("id");
//                
//		listaIdsParticipantes = credenciamentoEvParticipanteService.procurarParticipantePorIdEvento(idEvento);
//                System.out.println(listaIdsParticipantes.get(0));
//                for(Long id: listaIdsParticipantes){
//                listaParticipantes.add(ParticipanteService.findById(id));
//                
//                }
                
                listaParticipantes=ParticipanteService.findAll();
                request.setAttribute("id", idEvento);
                request.setAttribute("participantes", listaParticipantes);
		RequestDispatcher requestDispatcher = request
				.getRequestDispatcher("credenciamento.jsp");
		requestDispatcher.forward(request, response);

	}
}
